package GenericMethod;

import java.util.ArrayList;

import javax.swing.*;
import javax.swing.table.*;

import Exception.*;

public class ComboBoxMethod
{
	/**
	 * @param comboBox is the box with Integers values you have to send to the method
	 * <li>The value is <i>your_JComboBox</i></li>
	 * @param arrayList is the arrayList which contains your arrayList
	 * <li>The value is <i>your_arrayList</i></li>
	 */
	public void comboArrayInteger(JComboBox<Integer> comboBox, ArrayList<Integer> arrayList)
	{
		for(int item : arrayList)
		    comboBox.addItem(item);
	}
	
	/**
	 * @param comboBox is the box with Strings values you have to send to the method
	 * <li>The value is <i>your_JComboBox</i></li>
	 * @param arrayList is the arrayList which contains your arrayList
	 * <li>The value is <i>your_arrayList</i></li>
	 */
	public void comboArrayString(JComboBox<String> comboBox, ArrayList<String> arrayList)
	{
		for(String item : arrayList)
		    comboBox.addItem(item);
	}
	
	/**
	 * @param comboBox is the box with Objects values you have to send to the method
	 * <li>The value is <i>your_JComboBox</i></li>
	 * @param arrayList is the arrayList which contains your arrayList
	 * <li>The value is <i>your_arrayList</i></li>
	 */
	public void comboArrayObject(JComboBox<Object> comboBox, ArrayList<Object> arrayList)
	{
		for(Object item : arrayList)
			comboBox.addItem(item);
	}
	
	/**
	 * @param comboBox is the box with MyModel values you have to send to the method
	 * <li>The value is <i>your_JComboBox</i></li>
	 * @param TableModel is the TableModel you have to send to the method
	 * <li>The value is <i>your_TableModel</i></li>
	 * @param field
	 * <li>The value is : <i><b>column</b></i> or <i><b>row</b></i>
	 * <ol><i><b>column</b></i> the add of all value from a column in the model.</ol>
	 * <ol><i><b>row</b></i> the add of all value from a row in the model.</ol>
	 * @param number is a number from the row or from the column concerned
	 * @throws ComboModelException
	 */
	public void comboModel(JComboBox<Object> comboBox, TableModel TableModel, String field, int number) throws ComboModelException
	{
		if(field.equals("column"))
			for(int cpt = 0; cpt < TableModel.getRowCount(); cpt++)
				comboBox.addItem(TableModel.getValueAt(cpt, number));
		else
			if(field.equals("row"))
				for(int cpt = 0; cpt < TableModel.getColumnCount(); cpt++)
					comboBox.addItem(TableModel.getValueAt(number, cpt));
			else
			{
				String error = "The String value is NOT valid ! The value has to be \"column\" or \"row\"";
				throw new ComboModelException(error);
			}
	}
}
